package game.source.gui.hud;

import game.source.gui.GamePanel;
import game.source.gui.GuiComponent;

import java.awt.Color;
import java.awt.Font;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class Hud extends GuiComponent{
	private static PlayerLife		player;
	private	static GamePanel		panel;
	private	static BufferedImage	image;
	private static Font				font;
	private static boolean			gameOver;
	private static boolean			winner;
	private static boolean			paused;

	static{
		Hud.font = new Font("Comic Sans Ms", Font.PLAIN, 50);
		try {
			image = ImageIO.read(new File(Hud.class.getResource("/images/prices/newlife.png").getFile()));
		} catch (IOException e) {
			e.printStackTrace();
			System.err.println("Arquivo: "+Hud.class.getResource("/images/prices/newlife.png")+" não pode ser aberto");
			System.exit(1);
		}
		Hud.gameOver	= false;
		Hud.winner		= false;
		Hud.paused		= false;
	}

	public Hud(GamePanel panel, PlayerLife player){
		Hud.player		= player;
		Hud.panel		= panel;
	}

	public void gameOver(){
		Hud.gameOver = true;
	}
	public void gameWin(){
		Hud.winner = true;
	}

	public static void pause(){
		Hud.paused = true;
	}
	public static void play(){
		Hud.paused = false;
		Hud.panel.play();
	}

	public static boolean getPause(){
		return Hud.paused;
	}

	@Override
	public void show(long time){
		this.getGraphics().setColor(new Color(0));
		this.getGraphics().setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
		this.getGraphics().setFont(Hud.font);
		if(Hud.player.getLifes() < 10){
			this.getGraphics().drawString("0"+Hud.player.getLifes()+" x ",0,50);
		}else{
			this.getGraphics().drawString(Hud.player.getLifes()+" x ",0,50);
		}
		this.getGraphics().drawImage(Hud.image,125,0,null);
		if(Hud.gameOver){
			GameOver.show(this.getGraphics(), this.getPanelWidth(), this.getPanelHeight());
			Hud.panel.end();
		}else if(Hud.winner){
			WinGame.show(this.getGraphics(), this.getPanelWidth(), this.getPanelHeight());
			Hud.panel.end();
		}
		if(Hud.paused){
			GamePaused.show(this.getGraphics(), this.getPanelWidth(), this.getPanelWidth());
			Hud.panel.pause();
		}
	}

}
